package IU;

import Controladores.CtrlContrato;

import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import utiles.Validador;

import Controladores.CtrlProducto;
import Controladores.CtrlProveedor;
import Controladores.CtrlDetallecontrato;

import Entidades.Estadocontrato;
import Entidades.Proveedor;
import Entidades.Producto;
import Entidades.Contrato;
import Entidades.Detallecontrato;
import Entidades.Operario;

/**
 *OJO FALTA EL VERIFICAR ANTES DE GUARDAR!!!
 * OOJO NO FUNCIONA PARA GUARDAR MÀS DE UN PRODUCTO
 * @author  Laura
 * 
 * 
 */
public class ABMDetalleContrato extends javax.swing.JFrame {

    
    private String cantidad;
    private String precio;
    String oper;
    Operario o;
   
   
    Proveedor proveedor;
    TablaPersonalizada tableModel;
    private List lista;
    CtrlProveedor controladorprovee;
    CtrlProducto controladorproducto;
    CtrlContrato controladorcontrato;
    CtrlDetallecontrato controladordetallecontr;
    Producto producto;
    Validador validador;
    
   
    Estadocontrato estadocontrato = null;
    Contrato contrato = null;
    Operario operario = null;
    String cuartel;

    public ABMDetalleContrato(Proveedor prov, String fechaContrato, Contrato contr, String operario) {
        initComponents();
        oper = operario;
        jTextFieldUsuario2.setText(operario);
        proveedor = prov;
        controladorprovee = new CtrlProveedor();
        controladorproducto = new CtrlProducto();
        controladorcontrato = new CtrlContrato();
        controladordetallecontr = new CtrlDetallecontrato();
        jTextFieldRazonSocial.setText(proveedor.getRazonSocialProveedor());
        jTextFieldFechaContrato.setText(fechaContrato);
        contrato = contr;
      
        cargarComboNomProducto();
     }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldCantidadAlta = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        jTextFielpreciolistar = new javax.swing.JTextField();
        jTextFieldclasiflistar = new javax.swing.JTextField();
        jTextFielddescripcionlistar = new javax.swing.JTextField();
        jComboBoxNombreProd = new javax.swing.JComboBox();
        jLabel30 = new javax.swing.JLabel();
        jLabelDniCon1 = new javax.swing.JLabel();
        jLabelApellidoCon1 = new javax.swing.JLabel();
        jLabelTelCon1 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jButtonAgregar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldcuartel = new javax.swing.JTextField();
        jButtonBuscarProductoContrato = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableDetalle = new javax.swing.JTable();
        jButtonGuardar = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldRazonSocial = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldFechaContrato = new javax.swing.JTextField();
        jButtonSalir = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jTextFieldUsuario2 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Detalle de Contrato - Sistema Gestor de Pesaje para Bodegas");

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jTabbedPane1.setForeground(new java.awt.Color(102, 0, 102));
        jTabbedPane1.setFont(new java.awt.Font("Segoe UI", 3, 11));

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Detalle", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel2.setText("Cantidad:");

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Seleccionar Producto:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jTextFielpreciolistar.setEditable(false);
        jTextFielpreciolistar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jTextFieldclasiflistar.setEditable(false);
        jTextFieldclasiflistar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jTextFielddescripcionlistar.setEditable(false);
        jTextFielddescripcionlistar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jComboBoxNombreProd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jComboBoxNombreProdMousePressed(evt);
            }
        });
        jComboBoxNombreProd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxNombreProdActionPerformed(evt);
            }
        });

        jLabel30.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel30.setText("Descripción:");

        jLabelDniCon1.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelDniCon1.setText("Clasificación:");

        jLabelApellidoCon1.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelApellidoCon1.setText("Nombre:");

        jLabelTelCon1.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabelTelCon1.setText("Precio:");

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelDniCon1)
                    .addComponent(jLabel30)
                    .addComponent(jLabelApellidoCon1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBoxNombreProd, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addComponent(jTextFieldclasiflistar, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabelTelCon1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFielpreciolistar, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTextFielddescripcionlistar, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(33, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelApellidoCon1)
                    .addComponent(jComboBoxNombreProd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel30)
                    .addComponent(jTextFielddescripcionlistar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDniCon1)
                    .addComponent(jTextFieldclasiflistar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTelCon1)
                    .addComponent(jTextFielpreciolistar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(34, 34, 34))
        );

        jLabel8.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel8.setText("Kilogramos.");

        jButtonAgregar.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonAgregar.setForeground(new java.awt.Color(102, 0, 102));
        jButtonAgregar.setText("Agregar");
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel1.setText("Cuartel:");

        jButtonBuscarProductoContrato.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonBuscarProductoContrato.setForeground(new java.awt.Color(102, 0, 102));
        jButtonBuscarProductoContrato.setMnemonic('B');
        jButtonBuscarProductoContrato.setText("Buscar");
        jButtonBuscarProductoContrato.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBuscarProductoContratoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(57, 57, 57)
                        .addComponent(jButtonBuscarProductoContrato))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(35, 35, 35)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldcuartel, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(jTextFieldCantidadAlta, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel8)
                                .addGap(71, 71, 71)
                                .addComponent(jButtonAgregar)))))
                .addContainerGap(58, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButtonBuscarProductoContrato)
                    .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldcuartel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jButtonAgregar))
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jTextFieldCantidadAlta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Datos del contrato", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jTableDetalle.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jTableDetalle.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Producto", "Clasificación", "Cantidad", "Precio", "SubTotal"
            }
        ));
        jTableDetalle.setAutoscrolls(false);
        jTableDetalle.setFillsViewportHeight(true);
        jTableDetalle.setMinimumSize(new java.awt.Dimension(55, 55));
        jTableDetalle.setPreferredSize(new java.awt.Dimension(200, 42));
        jTableDetalle.setRowHeight(14);
        jTableDetalle.getTableHeader().setResizingAllowed(false);
        jScrollPane1.setViewportView(jTableDetalle);

        jScrollPane4.setViewportView(jScrollPane1);

        jButtonGuardar.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonGuardar.setForeground(new java.awt.Color(102, 0, 102));
        jButtonGuardar.setText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 572, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(62, 62, 62)
                .addComponent(jButtonGuardar)
                .addContainerGap(48, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(60, Short.MAX_VALUE)
                .addComponent(jButtonGuardar)
                .addGap(26, 26, 26))
        );

        jLabel4.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel4.setText("Razón Social Proveedor:");

        jTextFieldRazonSocial.setEditable(false);
        jTextFieldRazonSocial.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel9.setFont(new java.awt.Font("Segoe UI", 1, 11));
        jLabel9.setText("Fecha Contrato:");

        jTextFieldFechaContrato.setEditable(false);
        jTextFieldFechaContrato.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jButtonSalir.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButtonSalir.setForeground(new java.awt.Color(102, 0, 102));
        jButtonSalir.setText("Salir");
        jButtonSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSalirActionPerformed(evt);
            }
        });

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED), "Usuario Registrado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI", 3, 11), new java.awt.Color(102, 0, 102))); // NOI18N

        jTextFieldUsuario2.setEditable(false);
        jTextFieldUsuario2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldUsuario2, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextFieldUsuario2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        jButton1.setFont(new java.awt.Font("Segoe UI", 3, 12));
        jButton1.setForeground(new java.awt.Color(102, 0, 102));
        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel9))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldFechaContrato)
                            .addComponent(jTextFieldRazonSocial, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 493, Short.MAX_VALUE)
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(64, 64, 64))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(378, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(34, 34, 34)
                        .addComponent(jButtonSalir)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextFieldRazonSocial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTextFieldFechaContrato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(50, 50, 50)
                        .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(62, 62, 62))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSalir)
                    .addComponent(jButton1)))
        );

        jTabbedPane1.addTab("Alta Detalle Contrato", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1180, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 637, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1216)/2, (screenSize.height-686)/2, 1216, 686);
    }// </editor-fold>//GEN-END:initComponents

    private void refresh() {
        jTextFieldcuartel.setText("");
        jTextFieldCantidadAlta.setText("");

    }

private void jButtonSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSalirActionPerformed
    this.dispose();
}//GEN-LAST:event_jButtonSalirActionPerformed


private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed
    boolean ver = false;

    cantidad = jTextFieldCantidadAlta.getText();
    precio = jTextFielpreciolistar.getText();
    cuartel = jTextFieldcuartel.getText();
    //if (verificar(producto, cantidad, cuartel)) {
    //  if (ver == true) {
    System.out.println("dentro a guardar detalle contrato");
    System.out.println("producto " + producto);
    System.out.println("cantidad " + cantidad);

    System.out.println("precio " + precio);
    System.out.println("contrato: " + contrato);
    System.out.println("cuartel:" + cuartel);
    Detallecontrato pro = new Detallecontrato(producto, Float.parseFloat(cantidad), Float.parseFloat(precio), Integer.parseInt(cuartel), contrato);

    try{
    controladordetallecontr.guardarDetallecontrato(pro);
    System.out.println("guardo el iddetallecontrato: "+pro.getIdDetalleContrato());
    }catch(Exception e ){
        System.out.println(e);
    }
    JOptionPane.showMessageDialog(this, "El Detalle del contrato ha sido guardado exitosamente!", "Alta", JOptionPane.INFORMATION_MESSAGE);
   // }
    refresh();
    cargarTabla();

   
}//GEN-LAST:event_jButtonGuardarActionPerformed

  


    public void actualizarDatos() {
      
    }

    private void cargarTabla() {
        String[] encabezados = new String[5];
        encabezados[0] = "Producto";
        encabezados[1] = "Clasificación";
        encabezados[2] = "Cantidad";
        encabezados[3] = "Precio";
        encabezados[4] = "Cuartel";

        tableModel = new TablaPersonalizada(encabezados);
        jTableDetalle.setModel(tableModel);

        Vector fila = new Vector();
        Object product = jComboBoxNombreProd.getSelectedItem();
        fila.add(producto.getNombreProducto());
        fila.add(producto.getClasificacionproducto().getNombreclasificacion());
        fila.add(jTextFieldCantidadAlta.getText());
        fila.add(producto.getPrecio());
        fila.add(jTextFieldcuartel.getText());
        tableModel.addRow(fila);
    }

    private void limpiarCampos() {

    }

private void jComboBoxNombreProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxNombreProdActionPerformed
}//GEN-LAST:event_jComboBoxNombreProdActionPerformed


    private void jButtonBuscarProductoContratoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBuscarProductoContratoActionPerformed
        ///////////////
        System.out.println("");
       
        Object esteoperar = jComboBoxNombreProd.getSelectedItem();
        String nombrepro = esteoperar.toString();
        System.out.println("nombre producto " + nombrepro);
        try {
            producto = controladorproducto.buscarProductoNombre(nombrepro);
            System.out.println("producto:  " + producto);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "El producto ingresado no se ha encontrado.\n ", "Productos", JOptionPane.ERROR_MESSAGE);
        }
        if (producto != null) {

            jTextFielddescripcionlistar.setText(producto.getDescripcionProducto());
            jTextFieldclasiflistar.setText(producto.getClasificacionproducto().getNombreclasificacion());
            jTextFielpreciolistar.setText(String.valueOf(producto.getPrecio()));
        }
}//GEN-LAST:event_jButtonBuscarProductoContratoActionPerformed

    private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAgregarActionPerformed
        // TODO add your handling code here:
        //VALIDAR LA CANTIDAD EN FLOAT  Y MOSTRAR EN LA TABLA
        //CONTRATO TIENE: IDCONTRATO, FECHA, IDOPERARIO, IDPROVEEDOR, IDESTADOCONTRATO, OBSERVACIONES.
        //DETALLECONTRATO: IDDETALLECONTRATO, IDCONTRATO, IDPRODUCTO, CANTIDAD, PRECIO, CUARTEL.

            cargarTabla();
        
    }//GEN-LAST:event_jButtonAgregarActionPerformed

    private void jComboBoxNombreProdMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBoxNombreProdMousePressed
limpiarDatos();        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxNombreProdMousePressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtonBuscarProductoContrato;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JButton jButtonSalir;
    private javax.swing.JComboBox jComboBoxNombreProd;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelApellidoCon1;
    private javax.swing.JLabel jLabelDniCon1;
    private javax.swing.JLabel jLabelTelCon1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTableDetalle;
    private javax.swing.JTextField jTextFieldCantidadAlta;
    private javax.swing.JTextField jTextFieldFechaContrato;
    private javax.swing.JTextField jTextFieldRazonSocial;
    private javax.swing.JTextField jTextFieldUsuario2;
    private javax.swing.JTextField jTextFieldclasiflistar;
    private javax.swing.JTextField jTextFieldcuartel;
    private javax.swing.JTextField jTextFielddescripcionlistar;
    private javax.swing.JTextField jTextFielpreciolistar;
    // End of variables declaration//GEN-END:variables


    private void cargarComboNomProducto() {
        try {
            lista = controladorproducto.buscarTodosProducto();
            System.out.println("tamaño de la lista de Producto " + lista.size());
        } catch (Exception e) {
        }
        jComboBoxNombreProd.removeAllItems();
        for (int i = 0; i < lista.size(); i++) {
            Vector fila = new Vector();
            Producto prod = (Producto) lista.get(i);
            fila.add(prod.getDescripcionProducto());
            jComboBoxNombreProd.addItem(fila.get(0));
        }
        System.out.println("despues  de cargar combo nombre producto");
    }

    private boolean validar(String cantidad, String cuartel) {
        boolean ver = false;

        if (cantidad.equals("")||cuartel.equals("")) {
            JOptionPane.showMessageDialog(this, "Por favor ingrese la cantidad de producto!!!", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validador.getInstance().soloContieneNumerosYPuntos(cantidad)) {
            JOptionPane.showMessageDialog(this, "Cantidad incorrecta: Ingrese solo números para cantidad del producto!!!", "Error", JOptionPane.ERROR_MESSAGE);
        } else if (!validador.getInstance().soloContieneNumeros(cuartel)) {
            JOptionPane.showMessageDialog(this, "Cuartel incorrecto: Ingrese solo números para cuartel!!!", "Error", JOptionPane.ERROR_MESSAGE);
        }else {
            ver = true;
        }
        return ver;
    }

    private void limpiarDatos() {
        jTextFielddescripcionlistar.setText("");
            jTextFieldclasiflistar.setText("");
            jTextFielpreciolistar.setText("");
    }
}
